package it.davial.mgwt.client.ui.widget;

import it.davial.mgwt.client.ClientFactory;
import it.davial.mgwt.client.Patient;
import it.davial.mgwt.client.activities.patient.PatientView;
import it.davial.mgwt.client.activities.patient.detail.PatientDetailPlace;
import it.davial.mgwt.client.resources.ResourceAware;
import it.davial.mgwt.client.ui.widget.cell.PatientCell;

import java.util.logging.Logger;

import org.bsc.mgwt.client.widget.ProgressHeaderIndicator;
import org.soul.mgwt.client.widget.CsEditableCellList;

import com.googlecode.mgwt.ui.client.dialog.ConfirmDialog;
import com.googlecode.mgwt.ui.client.dialog.ConfirmDialog.ConfirmCallback;
import com.googlecode.mgwt.ui.client.widget.celllist.CellSelectedEvent;
import com.googlecode.mgwt.ui.client.widget.celllist.CellSelectedHandler;

public class PatientCellList  extends CsEditableCellList<Patient> implements ResourceAware{

//	private PatientCell cell = new PatientCell();
	private CellSelectedHandler addHandler;
	private CellSelectedHandler removeHandler;
	public PatientCellList(PatientView view, final ClientFactory clientFactory,PatientCell cell) {
		super(cell);
		this.clientFactory = clientFactory;
		this.view = view;
//		addStyleName(main)
		//addStyleName(mainCss.getRoundList().roundList());
		setRound(true);
		
		toggleEdit();
		
		setDefaultHandler(new CellSelectedHandler() {
			
			@Override
			public void onCellSelected(CellSelectedEvent event) {
				Patient u = getModel(event.getIndex());
				logger.info("element selected=" + u.getName());
				clientFactory.getPlaceController().goTo(new PatientDetailPlace(u));
				
			}
		});
	}

	private static final Logger logger = Logger.getLogger("TenantUserCellList");
//	private CustomerCell cell = new CustomerCell();
	private PatientView view;
	private ClientFactory clientFactory ;
	private final ProgressHeaderIndicator progressHeader  = new ProgressHeaderIndicator();

	@Override
	public void onCellSelectedToDelete(CellSelectedEvent event) {
		removeHandler.onCellSelected(event);

		
	}

	@Override
	public void onCellSelectedToAdd(CellSelectedEvent event) {
		addHandler.onCellSelected(event);
		
	}
	
	public void setCellDeleteHandler( CellSelectedHandler handler ){
		this.removeHandler = handler;
	}

	public void setCellAddHandler( CellSelectedHandler handler ){
		this.addHandler = handler;
	}

}
